package com.itheima.day15.TCP.test8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10009);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,
                10,
                1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        while (true) {
            Socket accept = ss.accept();
            ThreadSocket threadSocket = new ThreadSocket(accept);
            threadPoolExecutor.submit(threadSocket);
            // new Thread(threadSocket).start();
            //ss.close();
        }
    }
}
